package com.myapp.container;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.myapp.data.define.BaseBean;

public class DataContainer {
	/**
	 * 统一的数据Map容器
	 */
	private Map<String, Map<String, Object>> mapDatas = null;

	/**
	 * 统一的数据list容器
	 */
	private Map<String, List<? extends BaseBean>> listDatas = null;

	private static DataContainer dataContainer = null;

	public static DataContainer getInstance() {
		if (dataContainer == null) {
			dataContainer = new DataContainer();
		}
		return dataContainer;
	}

	private DataContainer() {
		if (mapDatas == null) {
			mapDatas = new HashMap<String, Map<String, Object>>();
		}

		if (listDatas == null) {
			listDatas = new HashMap<String, List<? extends BaseBean>>();
		}
	}

	public Map<String, Object> getMapDataByName(String name) {
		return this.mapDatas.get(name.toString());
	}

	public List<? extends BaseBean> getListDataByName(String name) {
		return this.listDatas.get(name.toString());
	}

	public void addMapData(String name, Map<String, Object> data) {
		if (this.mapDatas.containsKey(name)) {
			throw new IllegalArgumentException(String.format("Same name:[%s]",
					name));
		}

		this.mapDatas.put(name, data);
	}

	public void addListData(String name, List<? extends BaseBean> data) {
		if (this.mapDatas.containsKey(name)) {
			throw new IllegalArgumentException(String.format("Same name:[%s]",
					name));
		}

		this.listDatas.put(name, data);
	}
}
